<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/apple-touch-icon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="description" content="安全行业从业者，主要方向PC逆向附带安卓和Linux逆向，时不时喜欢写点BUG代码">
  <meta name="author" content="Cray">
  <meta name="keywords" content="">
  <title>V2ray(一)安装脚本 ~ 逆向安全博客</title>

  <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/5.12.1/css/all.min.css"  >
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css"  >
<link rel="stylesheet" href="https://cdn.staticfile.org/mdbootstrap/4.13.0/css/mdb.min.css"  >
<link rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/3.0.1/github-markdown.min.css"  >

<link rel="stylesheet" href="//at.alicdn.com/t/font_1067060_qzomjdt8bmp.css">



  <link rel="stylesheet" href="/lib/prettify/tomorrow.min.css"  >

<link rel="stylesheet" href="/css/main.css"  >


  <link rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css"  >


<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">


    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/">首页</a>
          </li>
        
          
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/archives/">归档</a>
          </li>
        
          
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/tags/">标签</a>
          </li>
        
          
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/links/">友链</a>
          </li>
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" false
      style="background: url('https://gitee.com/cve/BlogImg/raw/master/typora/image-20200825000046708.png') no-repeat center center;
      background-size: cover;">
    
        <div class="full-bg-img">
        <div class="mask rgba-black-light flex-center">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
                V2ray(一)安装脚本
              
            </span>

            
              <br>
              

              <p>
                
                  
                  &nbsp;<i class="far fa-chart-bar"></i>
                  <span class="post-count">
                    2.4k 字
                  </span>&nbsp;
                

                
                  
                  &nbsp;<i class="far fa-clock"></i>
                  <span class="post-count">
                      14 分钟
                  </span>&nbsp;
                

                
                  <!-- 不蒜子统计文章PV -->
                  
                  &nbsp;<i class="far fa-eye" aria-hidden="true"></i>&nbsp;
                  <span id="busuanzi_container_page_pv">
                    <span id="busuanzi_value_page_pv"></span> 次
                  </span>&nbsp;
                
              </p>
            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="py-5 z-depth-3" id="board">
        <div class="post-content mx-auto" id="post">
          <div class="markdown-body">
            <h2 id="基本知识"><a href="#基本知识" class="headerlink" title="基本知识"></a>基本知识</h2><h4 id="LInux中的一些特殊变量含义"><a href="#LInux中的一些特殊变量含义" class="headerlink" title="LInux中的一些特殊变量含义"></a>LInux中的一些特殊变量含义</h4><p>reference ：<a target="_blank" rel="noopener" href="http://c.biancheng.net/cpp/view/2739.html">http://c.biancheng.net/cpp/view/2739.html</a></p>
<table>
<thead>
<tr>
<th>变量</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>$0</td>
<td>当前脚本的文件名</td>
</tr>
<tr>
<td>$n</td>
<td>传递给脚本或函数的参数。n 是一个数字，表示第几个参数。例如，第一个参数是$1，第二个参数是$2。</td>
</tr>
<tr>
<td>$#</td>
<td>传递给脚本或函数的参数个数。</td>
</tr>
<tr>
<td>$*</td>
<td>传递给脚本或函数的所有参数。</td>
</tr>
<tr>
<td>$@</td>
<td>传递给脚本或函数的所有参数。被双引号(“ “)包含时，与 $* 稍有不同，下面将会讲到。</td>
</tr>
<tr>
<td>$?</td>
<td>上个命令的退出状态，或函数的返回值。</td>
</tr>
<tr>
<td>$$</td>
<td>当前Shell进程ID。对于 Shell 脚本，就是这些脚本所在的进程ID。</td>
</tr>
</tbody></table>
<h4 id="shift命令的含义"><a href="#shift命令的含义" class="headerlink" title="shift命令的含义"></a>shift命令的含义</h4><p><img src="https://gitee.com/CVE/BlogImg/raw/master/typora/image-20200719230335886.png" srcset="/img/loading.gif" alt="image-20200719230335886"></p>
<h2 id="V2-安装脚本"><a href="#V2-安装脚本" class="headerlink" title="V2 安装脚本"></a>V2 安装脚本</h2><pre><code class="bash">#!/bin/bash

# This file is accessible as https://install.direct/go.sh
# Original source is located at github.com/v2fly/v2ray-core/release/install-release.sh

# If not specify, default meaning of return value:
# 0: Success
# 1: System error
# 2: Application error
# 3: Network error

# CLI arguments
PROXY=&#39;&#39;
HELP=&#39;&#39;
FORCE=&#39;&#39;
CHECK=&#39;&#39;
REMOVE=&#39;&#39;
VERSION=&#39;&#39;
VSRC_ROOT=&#39;/tmp/v2ray&#39;
EXTRACT_ONLY=&#39;&#39;
LOCAL=&#39;&#39;
LOCAL_INSTALL=&#39;&#39;
DIST_SRC=&#39;github&#39;
ERROR_IF_UPTODATE=&#39;&#39;

CUR_VER=&quot;&quot;
NEW_VER=&quot;&quot;
VDIS=&#39;&#39;
ZIPFILE=&quot;/tmp/v2ray/v2ray.zip&quot;
V2RAY_RUNNING=0

CMD_INSTALL=&quot;&quot;
CMD_UPDATE=&quot;&quot;
SOFTWARE_UPDATED=0

SYSTEMCTL_CMD=$(command -v systemctl 2&gt;/dev/null)
SERVICE_CMD=$(command -v service 2&gt;/dev/null)

#######color code########
RED=&quot;31m&quot;      # Error message
GREEN=&quot;32m&quot;    # Success message
YELLOW=&quot;33m&quot;   # Warning message
BLUE=&quot;36m&quot;     # Info message


#########################
#获取传入的参数 
while [[ $# &gt; 0 ]]; 
do
    case &quot;$1&quot; in
        -p|--proxy)
        PROXY=&quot;-x $&#123;2&#125;&quot;
        shift # past argument
        ;;
        -h|--help)
        HELP=&quot;1&quot;
        ;;
        -f|--force)
        FORCE=&quot;1&quot;
        ;;
        -c|--check)
        CHECK=&quot;1&quot;
        ;;
        --remove)
        REMOVE=&quot;1&quot;
        ;;
        --version)
        VERSION=&quot;$2&quot;
        shift
        ;;
        --extract)
        VSRC_ROOT=&quot;$2&quot;
        shift
        ;;
        --extractonly)
        EXTRACT_ONLY=&quot;1&quot;
        ;;
        -l|--local)
        LOCAL=&quot;$2&quot;
        LOCAL_INSTALL=&quot;1&quot;
        shift
        ;;
        --source)
        DIST_SRC=&quot;$2&quot;
        shift
        ;;
        --errifuptodate)
        ERROR_IF_UPTODATE=&quot;1&quot;
        ;;
        *)
                # unknown option
        ;;
    esac
    shift # past argument or value
done

###############################
colorEcho()&#123;
    echo -e &quot;\033[$&#123;1&#125;$&#123;@:2&#125;\033[0m&quot; 1&gt;&amp; 2
&#125;

archAffix()&#123;
    case &quot;$&#123;1:-&quot;$(uname -m)&quot;&#125;&quot; in
        i686|i386)
            echo &#39;32&#39;
        ;;
        x86_64|amd64)
            echo &#39;64&#39;
        ;;
        *armv7*|armv6l)
            echo &#39;arm&#39;
        ;;
        *armv8*|aarch64)
            echo &#39;arm64&#39;
        ;;
        *mips64le*)
            echo &#39;mips64le&#39;
        ;;
        *mips64*)
            echo &#39;mips64&#39;
        ;;
        *mipsle*)
            echo &#39;mipsle&#39;
        ;;
        *mips*)
            echo &#39;mips&#39;
        ;;
        *s390x*)
            echo &#39;s390x&#39;
        ;;
        ppc64le)
            echo &#39;ppc64le&#39;
        ;;
        ppc64)
            echo &#39;ppc64&#39;
        ;;
        *)
            return 1
        ;;
    esac

    return 0
&#125;

zipRoot() &#123;
    unzip -lqq &quot;$1&quot; | awk -e &#39;
        NR == 1 &#123;
            prefix = $4;
        &#125;
        NR != 1 &#123;
            prefix_len = length(prefix);
            cur_len = length($4);

            for (len = prefix_len &lt; cur_len ? prefix_len : cur_len; len &gt;= 1; len -= 1) &#123;
                sub_prefix = substr(prefix, 1, len);
                sub_cur = substr($4, 1, len);

                if (sub_prefix == sub_cur) &#123;
                    prefix = sub_prefix;
                    break;
                &#125;
            &#125;

            if (len == 0) &#123;
                prefix = &quot;&quot;;
                nextfile;
            &#125;
        &#125;
        END &#123;
            print prefix;
        &#125;
    &#39;
&#125;

downloadV2Ray()&#123;
    rm -rf /tmp/v2ray
    mkdir -p /tmp/v2ray
    if [[ &quot;$&#123;DIST_SRC&#125;&quot; == &quot;jsdelivr&quot; ]]; then
        DOWNLOAD_LINK=&quot;https://cdn.jsdelivr.net/gh/v2ray/dist/v2ray-linux-$&#123;VDIS&#125;.zip&quot;
    else
        DOWNLOAD_LINK=&quot;https://github.com/v2fly/v2ray-core/releases/download/$&#123;NEW_VER&#125;/v2ray-linux-$&#123;VDIS&#125;.zip&quot;
    fi
    colorEcho $&#123;BLUE&#125; &quot;Downloading V2Ray: $&#123;DOWNLOAD_LINK&#125;&quot;
    curl $&#123;PROXY&#125; -L -H &quot;Cache-Control: no-cache&quot; -o $&#123;ZIPFILE&#125; $&#123;DOWNLOAD_LINK&#125;
    if [ $? != 0 ];then
        colorEcho $&#123;RED&#125; &quot;Failed to download! Please check your network or try again.&quot;
        return 3
    fi
    return 0
&#125;

installSoftware()&#123;
    COMPONENT=$1
    if [[ -n `command -v $COMPONENT` ]]; then
        return 0
    fi

    getPMT
    if [[ $? -eq 1 ]]; then
        colorEcho $&#123;RED&#125; &quot;The system package manager tool isn&#39;t APT or YUM, please install $&#123;COMPONENT&#125; manually.&quot;
        return 1
    fi
    if [[ $SOFTWARE_UPDATED -eq 0 ]]; then
        colorEcho $&#123;BLUE&#125; &quot;Updating software repo&quot;
        $CMD_UPDATE
        SOFTWARE_UPDATED=1
    fi

    colorEcho $&#123;BLUE&#125; &quot;Installing $&#123;COMPONENT&#125;&quot;
    $CMD_INSTALL $COMPONENT
    if [[ $? -ne 0 ]]; then
        colorEcho $&#123;RED&#125; &quot;Failed to install $&#123;COMPONENT&#125;. Please install it manually.&quot;
        return 1
    fi
    return 0
&#125;

# return 1: not apt, yum, or zypper
getPMT()&#123;
    if [[ -n `command -v apt-get` ]];then
        CMD_INSTALL=&quot;apt-get -y -qq install&quot;
        CMD_UPDATE=&quot;apt-get -qq update&quot;
    elif [[ -n `command -v yum` ]]; then
        CMD_INSTALL=&quot;yum -y -q install&quot;
        CMD_UPDATE=&quot;yum -q makecache&quot;
    elif [[ -n `command -v zypper` ]]; then
        CMD_INSTALL=&quot;zypper -y install&quot;
        CMD_UPDATE=&quot;zypper ref&quot;
    else
        return 1
    fi
    return 0
&#125;

normalizeVersion() &#123;
    if [ -n &quot;$1&quot; ]; then
        case &quot;$1&quot; in
            v*)
                echo &quot;$1&quot;
            ;;
            *)
                echo &quot;v$1&quot;
            ;;
        esac
    else
        echo &quot;&quot;
    fi
&#125;

# 1: new V2Ray. 0: no. 2: not installed. 3: check failed. 4: don&#39;t check.
getVersion()&#123;
    if [[ -n &quot;$VERSION&quot; ]]; then
        NEW_VER=&quot;$(normalizeVersion &quot;$VERSION&quot;)&quot;
        return 4
    else
        VER=&quot;$(/usr/bin/v2ray/v2ray -version 2&gt;/dev/null)&quot;
        RETVAL=$?
        CUR_VER=&quot;$(normalizeVersion &quot;$(echo &quot;$VER&quot; | head -n 1 | cut -d &quot; &quot; -f2)&quot;)&quot;
        TAG_URL=&quot;https://api.github.com/repos/v2fly/v2ray-core/releases/latest&quot;
        NEW_VER=&quot;$(normalizeVersion &quot;$(curl $&#123;PROXY&#125; -H &quot;Accept: application/json&quot; -H &quot;User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0&quot; -s &quot;$&#123;TAG_URL&#125;&quot; --connect-timeout 10| grep &#39;tag_name&#39; | cut -d\&quot; -f4)&quot;)&quot;

        if [[ $? -ne 0 ]] || [[ $NEW_VER == &quot;&quot; ]]; then
            colorEcho $&#123;RED&#125; &quot;Failed to fetch release information. Please check your network or try again.&quot;
            return 3
        elif [[ $RETVAL -ne 0 ]];then
            return 2
        elif [[ $NEW_VER != $CUR_VER ]];then
            return 1
        fi
        return 0
    fi
&#125;

stopV2ray()&#123;
    colorEcho $&#123;BLUE&#125; &quot;Shutting down V2Ray service.&quot;
    if [[ -n &quot;$&#123;SYSTEMCTL_CMD&#125;&quot; ]] || [[ -f &quot;/lib/systemd/system/v2ray.service&quot; ]] || [[ -f &quot;/etc/systemd/system/v2ray.service&quot; ]]; then
        $&#123;SYSTEMCTL_CMD&#125; stop v2ray
    elif [[ -n &quot;$&#123;SERVICE_CMD&#125;&quot; ]] || [[ -f &quot;/etc/init.d/v2ray&quot; ]]; then
        $&#123;SERVICE_CMD&#125; v2ray stop
    fi
    if [[ $? -ne 0 ]]; then
        colorEcho $&#123;YELLOW&#125; &quot;Failed to shutdown V2Ray service.&quot;
        return 2
    fi
    return 0
&#125;

startV2ray()&#123;
    if [ -n &quot;$&#123;SYSTEMCTL_CMD&#125;&quot; ] &amp;&amp; [[ -f &quot;/lib/systemd/system/v2ray.service&quot; || -f &quot;/etc/systemd/system/v2ray.service&quot; ]]; then
        $&#123;SYSTEMCTL_CMD&#125; start v2ray
    elif [ -n &quot;$&#123;SERVICE_CMD&#125;&quot; ] &amp;&amp; [ -f &quot;/etc/init.d/v2ray&quot; ]; then
        $&#123;SERVICE_CMD&#125; v2ray start
    fi
    if [[ $? -ne 0 ]]; then
        colorEcho $&#123;YELLOW&#125; &quot;Failed to start V2Ray service.&quot;
        return 2
    fi
    return 0
&#125;

installV2Ray()&#123;
    # Install V2Ray binary to /usr/bin/v2ray
    mkdir -p &#39;/etc/v2ray&#39; &#39;/var/log/v2ray&#39; &amp;&amp; \
    unzip -oj &quot;$1&quot; &quot;$2v2ray&quot; &quot;$2v2ctl&quot; &quot;$2geoip.dat&quot; &quot;$2geosite.dat&quot; -d &#39;/usr/bin/v2ray&#39; &amp;&amp; \
    chmod +x &#39;/usr/bin/v2ray/v2ray&#39; &#39;/usr/bin/v2ray/v2ctl&#39; || &#123;
        colorEcho $&#123;RED&#125; &quot;Failed to copy V2Ray binary and resources.&quot;
        return 1
    &#125;

    # Install V2Ray server config to /etc/v2ray
    if [ ! -f &#39;/etc/v2ray/config.json&#39; ]; then
        local PORT=&quot;$(($RANDOM + 10000))&quot;
        local UUID=&quot;$(cat &#39;/proc/sys/kernel/random/uuid&#39;)&quot;

        unzip -pq &quot;$1&quot; &quot;$2vpoint_vmess_freedom.json&quot; | \
        sed -e &quot;s/10086/$&#123;PORT&#125;/g; s/23ad6b10-8d1a-40f7-8ad0-e3e35cd38297/$&#123;UUID&#125;/g;&quot; - &gt; \
        &#39;/etc/v2ray/config.json&#39; || &#123;
            colorEcho $&#123;YELLOW&#125; &quot;Failed to create V2Ray configuration file. Please create it manually.&quot;
            return 1
        &#125;

        colorEcho $&#123;BLUE&#125; &quot;PORT:$&#123;PORT&#125;&quot;
        colorEcho $&#123;BLUE&#125; &quot;UUID:$&#123;UUID&#125;&quot;
    fi
&#125;


installInitScript()&#123;
    if [[ -n &quot;$&#123;SYSTEMCTL_CMD&#125;&quot; ]]; then
        if [[ ! -f &quot;/etc/systemd/system/v2ray.service&quot; &amp;&amp; ! -f &quot;/lib/systemd/system/v2ray.service&quot; ]]; then
            unzip -oj &quot;$1&quot; &quot;$2systemd/v2ray.service&quot; -d &#39;/etc/systemd/system&#39; &amp;&amp; \
            systemctl enable v2ray.service
        fi
    elif [[ -n &quot;$&#123;SERVICE_CMD&#125;&quot; ]] &amp;&amp; [[ ! -f &quot;/etc/init.d/v2ray&quot; ]]; then
        installSoftware &#39;daemon&#39; &amp;&amp; \
        unzip -oj &quot;$1&quot; &quot;$2systemv/v2ray&quot; -d &#39;/etc/init.d&#39; &amp;&amp; \
        chmod +x &#39;/etc/init.d/v2ray&#39; &amp;&amp; \
        update-rc.d v2ray defaults
    fi
&#125;

Help()&#123;
  cat - 1&gt;&amp; 2 &lt;&lt; EOF
./install-release.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
  -h, --help            Show help
  -p, --proxy           To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc
  -f, --force           Force install
      --version         Install a particular version, use --version v3.15
  -l, --local           Install from a local file
      --remove          Remove installed V2Ray
  -c, --check           Check for update
EOF
&#125;

remove()&#123;
    if [[ -n &quot;$&#123;SYSTEMCTL_CMD&#125;&quot; ]] &amp;&amp; [[ -f &quot;/etc/systemd/system/v2ray.service&quot; ]];then
        if pgrep &quot;v2ray&quot; &gt; /dev/null ; then
            stopV2ray
        fi
        systemctl disable v2ray.service
        rm -rf &quot;/usr/bin/v2ray&quot; &quot;/etc/systemd/system/v2ray.service&quot;
        if [[ $? -ne 0 ]]; then
            colorEcho $&#123;RED&#125; &quot;Failed to remove V2Ray.&quot;
            return 0
        else
            colorEcho $&#123;GREEN&#125; &quot;Removed V2Ray successfully.&quot;
            colorEcho $&#123;BLUE&#125; &quot;If necessary, please remove configuration file and log file manually.&quot;
            return 0
        fi
    elif [[ -n &quot;$&#123;SYSTEMCTL_CMD&#125;&quot; ]] &amp;&amp; [[ -f &quot;/lib/systemd/system/v2ray.service&quot; ]];then
        if pgrep &quot;v2ray&quot; &gt; /dev/null ; then
            stopV2ray
        fi
        systemctl disable v2ray.service
        rm -rf &quot;/usr/bin/v2ray&quot; &quot;/lib/systemd/system/v2ray.service&quot;
        if [[ $? -ne 0 ]]; then
            colorEcho $&#123;RED&#125; &quot;Failed to remove V2Ray.&quot;
            return 0
        else
            colorEcho $&#123;GREEN&#125; &quot;Removed V2Ray successfully.&quot;
            colorEcho $&#123;BLUE&#125; &quot;If necessary, please remove configuration file and log file manually.&quot;
            return 0
        fi
    elif [[ -n &quot;$&#123;SERVICE_CMD&#125;&quot; ]] &amp;&amp; [[ -f &quot;/etc/init.d/v2ray&quot; ]]; then
        if pgrep &quot;v2ray&quot; &gt; /dev/null ; then
            stopV2ray
        fi
        rm -rf &quot;/usr/bin/v2ray&quot; &quot;/etc/init.d/v2ray&quot;
        if [[ $? -ne 0 ]]; then
            colorEcho $&#123;RED&#125; &quot;Failed to remove V2Ray.&quot;
            return 0
        else
            colorEcho $&#123;GREEN&#125; &quot;Removed V2Ray successfully.&quot;
            colorEcho $&#123;BLUE&#125; &quot;If necessary, please remove configuration file and log file manually.&quot;
            return 0
        fi
    else
        colorEcho $&#123;YELLOW&#125; &quot;V2Ray not found.&quot;
        return 0
    fi
&#125;

checkUpdate()&#123;
    echo &quot;Checking for update.&quot;
    VERSION=&quot;&quot;
    getVersion
    RETVAL=&quot;$?&quot;
    if [[ $RETVAL -eq 1 ]]; then
        colorEcho $&#123;BLUE&#125; &quot;Found new version $&#123;NEW_VER&#125; for V2Ray.(Current version:$CUR_VER)&quot;
    elif [[ $RETVAL -eq 0 ]]; then
        colorEcho $&#123;BLUE&#125; &quot;No new version. Current version is $&#123;NEW_VER&#125;.&quot;
    elif [[ $RETVAL -eq 2 ]]; then
        colorEcho $&#123;YELLOW&#125; &quot;No V2Ray installed.&quot;
        colorEcho $&#123;BLUE&#125; &quot;The newest version for V2Ray is $&#123;NEW_VER&#125;.&quot;
    fi
    return 0
&#125;

main()&#123;
    #helping information
    [[ &quot;$HELP&quot; == &quot;1&quot; ]] &amp;&amp; Help &amp;&amp; return
    [[ &quot;$CHECK&quot; == &quot;1&quot; ]] &amp;&amp; checkUpdate &amp;&amp; return
    [[ &quot;$REMOVE&quot; == &quot;1&quot; ]] &amp;&amp; remove &amp;&amp; return

    local ARCH=$(uname -m)
    VDIS=&quot;$(archAffix)&quot;

    # extract local file
    if [[ $LOCAL_INSTALL -eq 1 ]]; then
        colorEcho $&#123;YELLOW&#125; &quot;Installing V2Ray via local file. Please make sure the file is a valid V2Ray package, as we are not able to determine that.&quot;
        NEW_VER=local
        rm -rf /tmp/v2ray
        ZIPFILE=&quot;$LOCAL&quot;
        #FILEVDIS=`ls /tmp/v2ray |grep v2ray-v |cut -d &quot;-&quot; -f4`
        #SYSTEM=`ls /tmp/v2ray |grep v2ray-v |cut -d &quot;-&quot; -f3`
        #if [[ $&#123;SYSTEM&#125; != &quot;linux&quot; ]]; then
        #    colorEcho $&#123;RED&#125; &quot;The local V2Ray can not be installed in linux.&quot;
        #    return 1
        #elif [[ $&#123;FILEVDIS&#125; != $&#123;VDIS&#125; ]]; then
        #    colorEcho $&#123;RED&#125; &quot;The local V2Ray can not be installed in $&#123;ARCH&#125; system.&quot;
        #    return 1
        #else
        #    NEW_VER=`ls /tmp/v2ray |grep v2ray-v |cut -d &quot;-&quot; -f2`
        #fi
    else
        # download via network and extract
        installSoftware &quot;curl&quot; || return $?
        getVersion
        RETVAL=&quot;$?&quot;
        if [[ $RETVAL == 0 ]] &amp;&amp; [[ &quot;$FORCE&quot; != &quot;1&quot; ]]; then
            colorEcho $&#123;BLUE&#125; &quot;Latest version $&#123;CUR_VER&#125; is already installed.&quot;
            if [ -n &quot;$&#123;ERROR_IF_UPTODATE&#125;&quot; ]; then
              return 10
            fi
            return
        elif [[ $RETVAL == 3 ]]; then
            return 3
        else
            colorEcho $&#123;BLUE&#125; &quot;Installing V2Ray $&#123;NEW_VER&#125; on $&#123;ARCH&#125;&quot;
            downloadV2Ray || return $?
        fi
    fi

    local ZIPROOT=&quot;$(zipRoot &quot;$&#123;ZIPFILE&#125;&quot;)&quot;
    installSoftware unzip || return $?

    if [ -n &quot;$&#123;EXTRACT_ONLY&#125;&quot; ]; then
        colorEcho $&#123;BLUE&#125; &quot;Extracting V2Ray package to $&#123;VSRC_ROOT&#125;.&quot;

        if unzip -o &quot;$&#123;ZIPFILE&#125;&quot; -d $&#123;VSRC_ROOT&#125;; then
            colorEcho $&#123;GREEN&#125; &quot;V2Ray extracted to $&#123;VSRC_ROOT%/&#125;$&#123;ZIPROOT:+/$&#123;ZIPROOT%/&#125;&#125;, and exiting...&quot;
            return 0
        else
            colorEcho $&#123;RED&#125; &quot;Failed to extract V2Ray.&quot;
            return 2
        fi
    fi

    if pgrep &quot;v2ray&quot; &gt; /dev/null ; then
        V2RAY_RUNNING=1
        stopV2ray
    fi
    installV2Ray &quot;$&#123;ZIPFILE&#125;&quot; &quot;$&#123;ZIPROOT&#125;&quot; || return $?
    installInitScript &quot;$&#123;ZIPFILE&#125;&quot; &quot;$&#123;ZIPROOT&#125;&quot; || return $?
    if [[ $&#123;V2RAY_RUNNING&#125; -eq 1 ]];then
        colorEcho $&#123;BLUE&#125; &quot;Restarting V2Ray service.&quot;
        startV2ray
    fi
    colorEcho $&#123;GREEN&#125; &quot;V2Ray $&#123;NEW_VER&#125; is installed.&quot;
    rm -rf /tmp/v2ray
    return 0
&#125;

main</code></pre>

            <hr>
          </div>
          <br>
          <div>
            <p>
            
            
              <span>
                <i class="iconfont icon-tag"></i>
                
                  <a class="hover-with-bg" href="/tags/porxy/">porxy</a>
                
              </span>
            
            </p>
            
              <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://zh.wikipedia.org/wiki/Wikipedia:CC_BY-SA_3.0%E5%8D%8F%E8%AE%AE%E6%96%87%E6%9C%AC" rel="nofollow noopener noopener">CC BY-SA 3.0协议</a> 。转载请注明出处！</p>
            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container">
        <div id="toc">
  <p class="h5"><i class="far fa-list-alt"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>
      </div>
    
  </div>
</div>

<!-- custom -->


<!-- Comments -->
<div class="col-lg-7 mx-auto nopadding-md">
  <div class="container comments mx-auto" id="comments">
    
      <br><br>
      
      
  <div class="disqus" style="width:100%">
    <div id="disqus_thread"></div>
    <script>
      var disqus_config = function () {
        this.page.url = 'http://cve.gitee.io/cve/2020/08/10/V2rayInstall/';
        this.page.identifier = '/2020/08/10/V2rayInstall/';
      };
      var oldLoad = window.onload;
      window.onload = function () {
        var d = document, s = d.createElement('script');
        s.type = 'text/javascript';
        s.src = '//' + 'crayon-1' + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
      };
    </script>
    <noscript>Please enable JavaScript to view the <a target="_blank" href="https://disqus.com/?ref_noscript" rel="nofollow noopener noopener">comments
        powered by Disqus.</a></noscript>
  </div>


    
  </div>
</div>

    
  </main>

  
    <a class="z-depth-1" id="scroll-top-button" href="#" role="button">
      <i class="fa fa-chevron-up scroll-top-arrow" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  <footer class="mt-5">
  <div class="text-center py-3">
    <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><b>Hexo</b></a>
    <i class="iconfont icon-love"></i>
    <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"> <b>Fluid</b></a>
    <br>

    
  
    <!-- 不蒜子统计PV -->
    
    &nbsp;<span id="busuanzi_container_site_pv"></span>总访问量 
          <span id="busuanzi_value_site_pv"></span> 次&nbsp;
  
  
    <!-- 不蒜子统计UV -->
    
    &nbsp;<span id="busuanzi_container_site_uv"></span>总访客数 
            <span id="busuanzi_value_site_uv"></span> 人&nbsp;
  
  <br>



    


    <!-- cnzz Analytics icon -->
    

  </div>
</footer>

<!-- SCRIPTS -->
<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script src="https://cdn.staticfile.org/popper.js/1.16.1/umd/popper.min.js" ></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script src="https://cdn.staticfile.org/mdbootstrap/4.13.0/js/mdb.min.js" ></script>
<script src="/js/main.js" ></script>


  <script src="/js/lazyload.js" ></script>



  
  <script src="https://cdn.staticfile.org/tocbot/4.10.0/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var navHeight = $('#navbar').height();
      var toc = $('#toc');
      var main = $('main');
      var tocT = navHeight + (toc.offset().top - main.offset().top);
      var tocLimMin = main.offset().top - navHeight;
      var tocLimMax = $('#comments').offset().top - navHeight;
      $(window).scroll(function () {
        var scroH = document.body.scrollTop + document.documentElement.scrollTop;
        if (tocLimMin <= scroH && scroH <= tocLimMax) {
          toc.css({
            'display': 'block',
            'position': 'fixed',
            'top': tocT,
          });
        } else if (scroH <= tocLimMin) {
          toc.css({
            'position': '',
            'top': '',
          });
        } else if (scroH > tocLimMax) {
          toc.css('display', 'none');
        }
      });
      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '.post-content',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        scrollSmooth: true,
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc > p').css('visibility', 'visible');
      }
    });
  </script>







  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>


<!-- Plugins -->



  <script src="https://cdn.staticfile.org/prettify/188.0.0/prettify.min.js" ></script>
  <script>
    $(document).ready(function () {
      $('pre').addClass('prettyprint  linenums');
      prettyPrint();
    })
  </script>





  <script src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      getSearchFile(path);
      this.onclick = null
    }
  </script>



  <script src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <script>
    $("#post img:not(.no-zoom img, img[no-zoom])").each(
      function () {
        var element = document.createElement("a");
        $(element).attr("data-fancybox", "images");
        $(element).attr("href", $(this).attr("src"));
        $(this).wrap(element);
      }
    );
  </script>












</body>
</html>
